<template>
	<div>
		<el-form ref="form" :rules="rules" :model="form" label-width="80px">
			<el-form-item label="权限名" prop="name"><el-input v-model="form.name"></el-input></el-form-item>
			<el-form-item label="请求地址" prop="url"><el-input v-model="form.url"></el-input></el-form-item>
			<el-form-item label="类别" prop="type">
				<el-radio-group v-model="form.type" size="small">
					<el-radio-button :label="1">目录</el-radio-button>
					<el-radio-button :label="2">页面</el-radio-button>
				</el-radio-group>
			</el-form-item>
			
			
			<el-form-item><el-button type="primary" plain @click="save">保存数据</el-button></el-form-item>
		</el-form>
	</div>
</template>

<script>
import axios from '../../utils/axiosutils.js';
export default {
	name: 'RoleEdit',
	props: ['editid', 'parentId'],
	data() {
		return {
			form: {
				id: '',
				name: '',
				url: '',
				type: 1,
				parentId: '1111'
			},
			defaultProps: {
				children: 'children',
				label: 'label'
			},
			rules: {
				name: [{ required: true, message: '权限名不能为空', trigger: 'blur' }, { min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur' }],
				url: [{ min: 1, max: 200, message: '长度在 1 到 200 个字符', trigger: 'blur' }],
				type: [{ required: true, message: '权限类别不能为空', trigger: 'blur' }]
			}
		};
	},
	created() {
		if(this.parentId){
			this.form.parentId = this.parentId;
		}
		if (this.editid) {
			
			axios.get(
				'/permission/getById',
				response => {
					this.form.id = response.obj.id;
					this.form.url = response.obj.url;
					this.form.name = response.obj.name;
					this.form.type = response.obj.type;
					this.form.parentId=response.obj.parentId
				},
				{
					id: this.editid
				}
			)
			
		}
		
		
		
	},
	methods: {
		
		save: function() {
			if (this.editid) {
	
				axios.post(
					'/permission/update',
					resp => {
						this.$emit('update:show', false);
						this.$emit('getData');
					},
					this.form
				);
			} else {
				axios.post(
					'/permission/add',
					resp => {
						this.$emit('update:show', false);
						this.$emit('getData');
					},
					this.form
				);
			}
		}
	}
};
</script>

<style></style>
